<template>
  <el-dialog
    class="contract-review-record-table-dialog"
    width="850px"
    :visible.sync="dialogVisible"
    title="合同评审记录表"
    :close-on-click-modal="false"
    :append-to-body="true"
    v-dialogDrag="true"
    @open="handleDialogOpen"
    @closed="handleDialogClosed"
  >
    <div style="font-size: 18px; font-weight: bold; text-align: center; margin-bottom: 15px;">合同评审记录</div>
    <div>
      <span>合同编号：</span>
      <el-input style="width: calc(100% - 100px);" v-model="recordDetail.agreementNumber" :clearable="false" placeholder=""></el-input>
    </div>
    <table class="contract-review-record-table" cellspacing="0" cellpadding="0" border>
      <tbody>
        <tr>
          <td class="center">委托单位</td>
          <td class="center">
            <el-input v-model="recordDetail.delegationOrganizationName" :clearable="false" placeholder=""></el-input>
          </td>
          <td class="center">评审时间</td>
          <td class="center">
            <el-date-picker
              v-model="recordDetail.evaluateDate"
              type="date"
              placeholder=""
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
            ></el-date-picker>
          </td>
        </tr>
        <tr>
          <td class="center">项目名称</td>
          <td class="center">
            <el-input v-model="recordDetail.projectName" :clearable="false" placeholder=""></el-input>
          </td>
          <td class="center">实施地点</td>
          <td class="center">
            <el-radio-group v-model="recordDetail.location">
              <el-radio :label="1">总部</el-radio>
              <el-radio :label="2">{{recordDetail.customLocation === 1 ? '甘肃七星' : '分场所'}}</el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td class="center">评审人员</td>
          <td colspan="3">
             <el-select
              style="width: 100%;"
              v-model="recordDetail.staffUserId"
              clearable
              filterable
              placeholder="请选择"
              multiple
            >
              <el-option
                v-for="item in userList"
                :key="item.userId"
                :label="item.nickName"
                :value="item.userId"
              ></el-option>
             </el-select>
          </td>
        </tr>
        <tr>
          <td class="center">合同性质</td>
          <td colspan="3">
            <el-radio-group v-model="recordDetail.quality">
              <el-radio :label="1">一般合同</el-radio>
              <el-radio :label="2">重大合同</el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td class="center" colspan="4">评审内容</td>
        </tr>
        <tr>
          <td class="center">资 质</td>
          <td colspan="3">
            委托项目是否在本公司业务授权范围内？
            <el-radio-group style="float: right;" v-model="recordDetail.competency">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
              <el-radio :label="3">不适用</el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td class="center">事 项</td>
          <td colspan="3">
            委托事项及相应要求是否明确？
            <el-radio-group style="float: right;" v-model="recordDetail.matter">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
              <el-radio :label="3">不适用</el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td class="center">合 规</td>
          <td colspan="3">
            委托事项是否符合现行的法律法规？
            <el-radio-group style="float: right;" v-model="recordDetail.compliance">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
              <el-radio :label="3">不适用</el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td class="center">检测方法</td>
          <td colspan="3">
            合同内容是否明确了所使用的检测方法，检测方法是否满足服务项目？
            <el-radio-group style="float: right;" v-model="recordDetail.detectionMethod">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
              <el-radio :label="3">不适用</el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td class="center">设 备</td>
          <td colspan="3">
            检测使用的仪器设备性能、数量是否满足服务项目？
            <el-radio-group style="float: right;" v-model="recordDetail.equipment_1">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
              <el-radio :label="3">不适用</el-radio>
            </el-radio-group>
            <br/>
            检测使用的仪器设备检定证书或校准证书是否在有效期内
            <el-radio-group style="float: right;" v-model="recordDetail.equipment_2">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
              <el-radio :label="3">不适用</el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td class="center">环 境</td>
          <td colspan="3">
            是否对检测环境有特殊要求？
            <el-radio-group style="float: right;" v-model="recordDetail.environment">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
              <el-radio :label="3">不适用</el-radio>
            </el-radio-group>
            <br/>
            如有，特殊要求：
            <el-input style="height: auto; width: 500px;" v-model="recordDetail.environmentRequire" :clearable="false" placeholder=""></el-input>
          </td>
        </tr>
        <tr>
          <td class="center">人 员</td>
          <td colspan="3">
            项目检测人员资质是否可满足服务项目？
            <el-radio-group style="float: right;" v-model="recordDetail.personnel_1">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
              <el-radio :label="3">不适用</el-radio>
            </el-radio-group>
            <br/>
            项目检测人员是否经过公司能力确认与授权？
            <el-radio-group style="float: right;" v-model="recordDetail.personnel_2">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
              <el-radio :label="3">不适用</el-radio>
            </el-radio-group>
            <br/>
            项目检测人员数量是否满足？
            <el-radio-group style="float: right;" v-model="recordDetail.personnel_3">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
              <el-radio :label="3">不适用</el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td class="center">分 包</td>
          <td colspan="3">
            合同内容涉及的分包安排是否符合相关要求？
            <el-radio-group style="float: right;" v-model="recordDetail.subcontract">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
              <el-radio :label="3">不适用</el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td class="center">交付期限</td>
          <td colspan="3">
            是否可在约定交付期限内交付报告？
            <el-radio-group style="float: right;" v-model="recordDetail.deadline">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
              <el-radio :label="3">不适用</el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td class="center">资  金</td>
          <td colspan="3">
            双方价款是否达成共识？
            <el-radio-group style="float: right;" v-model="recordDetail.capital">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="2">否</el-radio>
              <el-radio :label="3">不适用</el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td class="center">交付方式</td>
          <td colspan="3">
            <el-radio-group v-model="recordDetail.mailMethod">
              <el-radio :label="1">邮寄</el-radio>
              <el-radio :label="0">自取</el-radio>
            </el-radio-group>
          </td>
        </tr>
        <tr>
          <td class="center">其 他</td>
          <td colspan="3">
            <el-input v-model="recordDetail.otherRemarks" :clearable="false" placeholder=""></el-input>
          </td>
        </tr>
        <tr>
          <td class="center">评审意见：</td>
          <td colspan="3">
            <el-radio-group v-model="recordDetail.opinion">
              <el-radio :label="1">可以签订合同</el-radio>
              <el-radio :label="2">不同意签订合同</el-radio>
              <el-radio :label="3">需修改后签订</el-radio>
            </el-radio-group>
          </td>
        </tr>
      </tbody>
    </table>

    <!-- <table class="contract-review-record-table" cellspacing="0" cellpadding="0" border>
      <thead>
        <tr>
          <th colspan="8" rowspan="2">
            <span style="font-size: 18px;">合同评审记录表</span>
          </th>
          <th width="80px">文件号</th>
          <th class="center" width="150px">CR/ZR-01-13</th>
        </tr>
        <tr>
          <th>版本号</th>
          <th class="center">第1版/第0次修改</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td class="center" width="150px">委托单位</td>
          <td class="center" colspan="7">张掖市疾病预防控制中心</td>
          <td class="center">合同金额</td>
          <td class="center" style="padding: 0 0;">
            <el-input v-model="recordDetail.signAmount" :clearable="false" placeholder=""></el-input>
          </td>
        </tr>
        <tr>
          <td class="center">项目名称</td>
          <td class="center" colspan="7">张掖市医用辐射防护现场检测</td>
          <td class="center">合同编号</td>
          <td class="center" style="padding: 0 0;">
            <el-input v-model="recordDetail.agreementNumber" :clearable="false" placeholder=""></el-input>
          </td>
        </tr>
        <tr>
          <td class="center">项目概况</td>
          <td class="center" colspan="9">
            依据国家法律、法规及中心体系文件的规定，完成甘南州九台放射设备的医用辐射防护现场检测工作，并出具检测报告。
          </td>
        </tr>
        <tr>
          <td colspan="10">
            <div>
              <span style="font-size: 16px;">评审内容:</span>
              <div style="position: relative; line-height: 35px;">
                1.客户的要求是否符合国家法律、放射卫生标准规范要求
                <el-radio-group style="position: absolute; right: 0;" v-model="recordDetail.options_1">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="2">否</el-radio>
                </el-radio-group>
              </div>
              <div style="position: relative; line-height: 35px;">
                2.检测、评价项目是否在本中心检测、评价资质范围之内
                <el-radio-group style="position: absolute; right: 0;" v-model="recordDetail.options_2">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="2">否</el-radio>
                </el-radio-group>
              </div>
              <div style="position: relative; line-height: 35px;">
                3.检测、评价项目及其相应的要求是否在合同/协议中明确
                <el-radio-group style="position: absolute; right: 0;" v-model="recordDetail.options_3">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="2">否</el-radio>
                </el-radio-group>
              </div>
              <div style="position: relative; line-height: 35px;">
                4.为客户进行的检测项目是否配备正确的仪器设备
                <el-radio-group style="position: absolute; right: 0;" v-model="recordDetail.options_4">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="2">否</el-radio>
                </el-radio-group>
              </div>
              <div style="position: relative; line-height: 35px;">
                5.专业技术检测、评价人员在数量与技能方面能否满足客户要求
                <el-radio-group style="position: absolute; right: 0;" v-model="recordDetail.options_5">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="2">否</el-radio>
                </el-radio-group>
              </div>
              <div style="position: relative; line-height: 35px;">
                6.本中心在现有检测、评价工作量前提下能否按时提供报告
                <el-radio-group style="position: absolute; right: 0;" v-model="recordDetail.options_6">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="2">否</el-radio>
                </el-radio-group>
              </div>
              <div style="position: relative; line-height: 35px;">
                7.现有的检测、评价方法能否满足本项目的检测、评价
                <el-radio-group style="position: absolute; right: 0;" v-model="recordDetail.options_7">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="2">否</el-radio>
                </el-radio-group>
              </div>
              <div style="position: relative; line-height: 35px;">
                8.现有的检测标准物质能否满足本项目的检测
                <el-radio-group style="position: absolute; right: 0;" v-model="recordDetail.options_8">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="2">否</el-radio>
                </el-radio-group>
              </div>
              <div style="position: relative; line-height: 35px;">
                9.为客户进行的检测是否须分包检测项目（委托项低于20%）
                <el-radio-group style="position: absolute; right: 0;" v-model="recordDetail.options_9">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="2">否</el-radio>
                </el-radio-group>
              </div>
              <div style="position: relative; line-height: 35px;">
                10.该项目报价是否符合有关收费规定和标准
                <el-radio-group style="position: absolute; right: 0;" v-model="recordDetail.options_10">
                  <el-radio :label="1">是</el-radio>
                  <el-radio :label="2">否</el-radio>
                </el-radio-group>
              </div>
              <div style="position: relative; line-height: 35px;">
                11.其他
              </div>
            </div>
          </td>
        </tr>
        <tr>
          <td colspan="10">
            <div>
              <span style="font-size: 16px;">评审结论:</span>
              <el-checkbox-group v-model="recordDetail.conclusion">
                <el-checkbox style="line-height: 30px;" label="1">本中心能采用适当的方法,完成客户要求的全部检测、评价项目。</el-checkbox><br/>
                <el-checkbox style="line-height: 30px;" label="2">人员技能、专业技术、检测设备、环境条件、检测方法等能满足客户的要求。</el-checkbox><br/>
                <el-checkbox style="line-height: 30px;" label="3">在合同期间,能保证按时提供检测、评价报告。</el-checkbox><br/>
                <el-checkbox style="line-height: 30px;" label="4">其他：</el-checkbox>
              </el-checkbox-group>
            </div>
          </td>
        </tr>
        <tr>
          <td class="center">参加评审部门</td>
          <td class="center" colspan="8">评审意见（同意或附意见）</td>
          <td class="center">评审人签字</td>
        </tr>
        <tr>
          <td class="center">综合办公室</td>
          <td class="center" style="padding: 0 0;" colspan="8">
            <el-input v-model="recordDetail.audit.generalAudit" :clearable="false" placeholder=""></el-input>
          </td>
          <td class="center" style="padding: 0 0;">
            <el-input v-model="recordDetail.audit.generalBy" :clearable="false" placeholder=""></el-input>
          </td>
        </tr>
        <tr>
          <td class="center">评价室</td>
          <td class="center" style="padding: 0 0;" colspan="8">
            <el-input v-model="recordDetail.audit.evaluateAudit" :clearable="false" placeholder=""></el-input>
          </td>
          <td class="center" style="padding: 0 0;">
            <el-input v-model="recordDetail.audit.evaluateBy" :clearable="false" placeholder=""></el-input>
          </td>
        </tr>
        <tr>
          <td class="center">检测室</td>
          <td class="center" style="padding: 0 0;" colspan="8">
            <el-input v-model="recordDetail.audit.detectionAudit" :clearable="false" placeholder=""></el-input>
          </td>
          <td class="center" style="padding: 0 0;">
            <el-input v-model="recordDetail.audit.detectionBy" :clearable="false" placeholder=""></el-input>
          </td>
        </tr>
        <tr>
          <td class="center">技术负责人</td>
          <td class="center" style="padding: 0 0;" colspan="8">
            <el-input v-model="recordDetail.audit.technologyAudit" :clearable="false" placeholder=""></el-input>
          </td>
          <td class="center" style="padding: 0 0;">
            <el-input v-model="recordDetail.audit.technologyBy" :clearable="false" placeholder=""></el-input>
          </td>
        </tr>
        <tr>
          <td class="center">质量负责人</td>
          <td class="center" style="padding: 0 0;" colspan="8">
            <el-input v-model="recordDetail.audit.qualityAudit" :clearable="false" placeholder=""></el-input>
          </td>
          <td class="center" style="padding: 0 0;">
            <el-input v-model="recordDetail.audit.qualityBy" :clearable="false" placeholder=""></el-input>
          </td>
        </tr>
        <tr>
          <td class="center">中心领导最终意见：</td>
          <td class="center" style="padding: 0 0;" colspan="8">
            <el-input v-model="recordDetail.audit.lastAudit" :clearable="false" placeholder=""></el-input>
          </td>
          <td class="center" style="padding: 0 0;">
            <el-input v-model="recordDetail.audit.lastBy" :clearable="false" placeholder=""></el-input>
          </td>
        </tr>
      </tbody>
    </table> -->

    <div class="dialog-footer" slot="footer">
      <el-button style="margin-right: 0px" type="primary" @click="handleSubmit">保存</el-button>
      <el-button style="margin-left: 30px" type="primary" @click="handleGenerate" v-if="entry == 2">生成</el-button>
      <el-button style="margin-left: 30px" type="primary" @click="handlePrint" v-if="entry == 2 && recordDetail.contractReviewOssId">预览</el-button>
      <el-button style="margin-left: 30px" @click="dialogVisible = false">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listUser } from '@/api/system/user'
import {
  getContractReviewContentById,
  getContractReviewContentById2,
  saveContractReviewRecordContent,
  saveContractReviewRecordContent2,
  generateContractReviewContent,
  generateContractReviewContent2
} from '@/api/slides/contractTask'
import { listByIds } from '@/api/system/oss'

export default {
  name: 'ContractReviewRecordTableDialog',
  dicts: [],
  props: {
    show: {
      type: Boolean,
      default: false,
    },
    row: {
      type: Object,
      default: () => ({})
    },
    data: {
      type: Object,
      default: () => ({})
    },
    // 1合同评审页面进入、2收入合同页面进入
    entry: {
      type: Number,
      default: 1
    }
    // totalPrice: {
    //   type: [Number, String],
    //   default: 0
    // }
  },
  computed: {
    dialogVisible: {
      get() {
        return this.show
      },
      set(value) {
        this.$emit('update:show', value)
      }
    }
  },
  data() {
    return {
      userList: [],
      tableLoading: false,
      recordDetail: {}
    }
  },
  created() {
    this.initRecordDetail()
  },
  methods: {
    // 初始化表格字段
    initRecordDetail() {
      this.recordDetail = {
        agreementNumber: '',
        evaluateDate: '',
        projectName: '',
        location: '',
        staffUserId: [],
        staff: [],
        quality: '',
        competency: '',
        matter: '',
        compliance: '',
        detectionMethod: '',
        equipment_1: '',
        equipment_2: '',
        environment: '',
        environmentRequire: '',
        personnel_1: '',
        personnel_2: '',
        personnel_3: '',
        subcontract: '',
        deadline: '',
        capital: '',
        mailMethod: '',
        otherRemarks: '',
        opinion: '',
        customLocation: 0,

        // signAmount: '',
        // agreementNumber: '',
        // options_1: '',
        // options_2: '',
        // options_3: '',
        // options_4: '',
        // options_5: '',
        // options_6: '',
        // options_7: '',
        // options_8: '',
        // options_9: '',
        // options_10: '',
        // conclusion: [],
        // audit: {
        //   generalAudit: '',
        //   generalBy: '',
        //   evaluateAudit: '',
        //   evaluateBy: '',
        //   detectionAudit: '',
        //   detectionBy: '',
        //   technologyAudit: '',
        //   technologyBy: '',
        //   qualityAudit: '',
        //   qualityBy: '',
        //   lastAudit: '',
        //   lastBy: ''
        // }
      }
    },
    // 弹框打开时
    handleDialogOpen() {
      if (this.row.tasksContractId || this.row.agreementId) {
        this.getContractReviewTableContent()
      } else {
        if (JSON.stringify(this.data) !== '{}') {
          this.recordDetail = JSON.parse(JSON.stringify(this.data))
        }
        // this.recordDetail.signAmount = this.recordDetail.signAmount || this.totalPrice
      }

      if (this.userList.length <= 0) {
        listUser({ pageNum: 1, pageSize: 10000 }).then(res => {
          this.userList = res.rows || []
        }).catch(err => {})
      }
    },
    // 弹框关闭时
    handleDialogClosed() {
      this.tableLoading = false
      if (this.row.tasksContractId) {
        this.initRecordDetail()
      }
    },
    // 获取合同评审记录表内容
    getContractReviewTableContent() {
      this.tableLoading = true
      let fn = null
      let id = null
      if (this.entry === 1) {
        id = this.row.tasksContractId
        fn = getContractReviewContentById
      } else if (this.entry === 2) {
        id = this.row.agreementId
        fn = getContractReviewContentById2
      }
      fn(id).then(res => {
        this.tableLoading = false
        if (res.data.record) {
          this.recordDetail = res.data.record
          // this.recordDetail.conclusion = this.recordDetail.conclusion ? this.recordDetail.conclusion.split(',') : []
        }
        this.recordDetail.tasksContractId = res.data.tasksContractId
        this.recordDetail.tasksContractReviewId = res.data.tasksContractReviewId
        this.recordDetail.contractReviewOssId = res.data.contractReviewOssId
        this.recordDetail.customLocation = res.data.customLocation
      }).catch(err => {
        this.tableLoading = false
      })
    },
    // 获取保存参数数据
    getFormData() {
      const data = JSON.parse(JSON.stringify(this.recordDetail))
      if (this.entry == 1) {
        data.tasksContractId = this.row.agreementId
      } else if (this.entry == 2) {
        data.tasksContractId = this.row.agreementId
      }
      // data.conclusion = data.conclusion.join(',')
      return data
    },
    // 提交
    handleSubmit() {
      if (this.entry == 1) {
        if (!this.row.tasksContractId) {
          this.dialogVisible = false
          this.$emit('temp-save', this.recordDetail)
          return
        }
        const data = this.getFormData()
        let fn = saveContractReviewRecordContent
        fn(data).then(res => {
          this.$message.success('保存成功')
          this.dialogVisible = false
          this.$emit('refresh')
        }).catch(err => {})
      } else if (this.entry == 2) {
        const data = this.getFormData()
        let fn = saveContractReviewRecordContent2
        fn(data).then(res => {
          this.$message.success('保存成功')
          this.getContractReviewTableContent()
        }).catch(err => {})
      }
    },
    handleGenerate() {
      if (this.entry == 1) {
        const tasksContractId = this.recordDetail.tasksContractId
        generateContractReviewContent(tasksContractId).then((res) => {
          this.$message.success('生成成功')
          this.getContractReviewTableContent()
        }).catch((err) => {})
      } else {
        const tasksContractId = this.recordDetail.tasksContractId
        generateContractReviewContent2(tasksContractId).then((res) => {
          this.$message.success('生成成功')
          this.getContractReviewTableContent()
        }).catch((err) => {})
      }
    },
    handlePrint() {
      listByIds(this.recordDetail.contractReviewOssId).then((res) => {
				const fileUrl = res.data[0].url
				window.open(fileUrl, 'PDF', '')
			}).catch((err) => {})
    }
  }
}
</script>

<style lang="scss" scoped>
.contract-review-record-table-dialog {

  ::v-deep .el-dialog {
    overflow: unset !important;
  }

  ::v-deep .el-dialog__body {
    padding: 20px 20px 30px;
    max-height: 80vh;
    overflow-y: auto;
  }

  ::v-deep .el-input__inner {
    border: none;
  }

  table.contract-review-record-table {
    width: 100%;
    border-color: #dfe6ec;
    border-collapse: collapse;

    thead tr th {
      height: 34px;
      text-align: center;
    }

    tbody tr td {
      padding: 10px 10px;
      height: 40px;
    }
    tbody tr td.center {
      text-align: center;
    }

    ::v-deep .el-input {
      width: 100%;
      height: 100%;
    }
    ::v-deep .el-input .el-input__inner {
      width: 100%;
      height: 100%;
      border: none;
    }

    ::v-deep .el-select .el-input__suffix {
      display: none;
    }

    ::v-deep .el-textarea {
      width: 100%;
      height: 100%;
    }
    ::v-deep .el-textarea .el-textarea__inner {
      width: 100%;
      min-height: 100% !important;
      border: none;
      resize: none;
    }

    ::v-deep .el-date-editor {
      width: 100%;
      height: 100%;
    }
    ::v-deep .el-date-editor .el-input__inner {
      padding: 0 10px;
      width: 100%;
      height: 100%;
      border: none;
    }
    ::v-deep .el-date-editor .el-input__prefix {
      display: none;
    }
  }
}
</style>
